#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    ListNode* EntryNodeOfLoop(ListNode* pHead)
    {
        ListNode* last, * fast;
        last = fast = pHead;
        while (fast != nullptr && fast->next != nullptr)
        {
            last = last->next;
            fast = fast->next->next;
            if (last == fast)
            {
                ListNode* cur = pHead;
                while (cur != last)
                {
                    cur = cur->next;
                    last = last->next;
                }
                return cur;
            }
        }
        return nullptr;
    }
};

